from pydoc import plain

import evaluate
from evaluate.visualization import radar_plot

# 查看支持的评估函数
print(evaluate.list_evaluation_modules(include_community=False))

# 加载评估函数
accuracy = evaluate.load("accuracy")
# 打印评估指标
print(accuracy.description)
# 评估指标计算-全局计算

result=accuracy.compute(references=[0,1,2,0,1],predictions=[0,1,1,2,1])
print(result)

# 批量处理
accuracy = evaluate.load("accuracy")
for ref,pred in zip([0,1,2,0,1],[0,1,1,2,1]):
    result=accuracy.add(references=ref,predictions=pred)
print(accuracy.compute())
accuracy = evaluate.load("accuracy")
for ref,pred in zip([[0,1,2,0,1],[0,1,1,2,1]],[[0,1,0,1,2],[0,1,1,2,1]]):
    result=accuracy.add_batch(references=ref,predictions=pred)
print(accuracy.compute())


# 多个评估指标计算

clf_metrics=evaluate.combine(["accuracy","f1"])
print(clf_metrics)
print(clf_metrics.compute(references=[0,1,0,0,1],predictions=[0,1,1,1,1]))
# 评估结果对比可视化

# import pandas as pd
# df=pd.DataFrame({'references':[0,1,0,0,1],'predictions':[0,1,1,1,1]})
# print(df)
# clf_metrics.plot(df, x="references", y="predictions", kind="bar")


data=[
    {"accuracy":0.99,"f1":0.98},
    {"accuracy":0.98,"f1":0.99},
    {"accuracy":0.21,"f1":0.33},
    {"accuracy":0.96,"f1":0.96},
]

model_name=["bert-base-uncased","roberta-base","distilbert-base-uncased","albert-base-v2"]

plot=radar_plot(data,model_name)
plot.show()
print()